<template>
  <div>
    <div class="login-container">
      <div class="username">
        登入名称:<input
          ref="myName"
          type="text"
          name=""
          id="uname"
          placeholder="输入登入名称"
        />
      </div>
      <div class="passwd">
        登入密码:<input
          ref="myPwd"
          type="password"
          name=""
          id="upwd"
          placeholder="输入登入密码"
          @keyup.enter="logEnt"
        />
      </div>
      <div class="btnBox">
        <button class="btnChange" @click="reset">重置</button>
        <button class="btnlogin" @click="login">登入</button>
        <div class="loginBg">
          <img src="@/assets/logo.png" alt="" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      nsername: "admin",
      passwd: "123456",
    };
  },
  methods: {
    // 点击登入按钮
    login() {
      // 判断用户是否输入正确的用户名和密码
      if ((this.$refs.myName.value === "admin") & (this.$refs.myPwd.value === "123456")) {
        // this.$router.replace('/back');
        localStorage.setItem('token', 'Bearer xxx')
        this.$router.replace('/back');
      } else {
        localStorage.removeItem('token')
        alert('用户或密码错误')
      }
    },
    // 点击重置按钮，输入框里面的内容全部清空
  reset () {
    localStorage.removeItem('token')
    this.$refs.myPwd.value = ""
    this.$refs.myName.value = ""
  },
  // 点击回车判断是否输入正确的用户和密码
  logEnt(){
    if ((this.$refs.myName.value === "admin") & (this.$refs.myPwd.value === "123456")) {
        // this.$router.replace('/back');
        localStorage.setItem('token', 'Bearer xxx')
        this.$router.replace('/back');
      } else {
        localStorage.removeItem('token')
        alert('用户或密码错误')
      }
  }
  },
};
</script>

<style lang="less" scoped>
.login-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400px;
  height: 250px;
  background-color: white;
  // background-color: #0078ff;
  // border:1px solid red;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  padding: 10px;
  .username {
    margin-top: 100px;
    // background-color: red;
    height: 30px;
    line-height: 30px;
    #uname {
      height: 28px;
      width: 300px;
      outline: none;
      border: 1px solid #ccc;
      padding-left: 5px;
    }
  }
  .passwd {
    // position: relative;
    margin-top: 10px;
    // background-color: red;
    height: 30px;
    line-height: 30px;
    #upwd {
      height: 28px;
      width: 300px;
      outline: none;
      border: 1px solid #ccc;
      padding-left: 5px;
    }
  }
  .btnBox {
    position: relative;
    margin-top: 10px;
    // background-color: red;
    height: 40px;
    line-height: 40px;
    text-align: right;
    padding-right: 17px;
    .btnChange {
      width: 50px;
      height: 35px;
      color: white;
      background-color: #707b82;
      border: 0;
      border-radius: 5px;
      margin-right: 5px;
    }
    .btnlogin {
      width: 50px;
      height: 35px;
      color: white;
      background-color: #0078ff;
      border: 0;
      border-radius: 5px;
      margin-right: 5px;
    }
    .loginBg {
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      top: -265px;
      width: 150px;
      height: 150px;
      border-radius: 50%;
      background-color: white;
      overflow: hidden;
      border: 1px solid #eee;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>